package com.up.vms.application.common.utils.json;
import java.io.Serializable;

/**
 * @author ZhangSuchao
 * @create 2019/1/12
 * @since 1.0.0
 */
public class JsonResult implements Serializable {
    public final static String RET_SUCCESS = "200";
    public final static String RET_ERROR = "500";
    private static final long serialVersionUID = 1L;
    private String status = "400";
    private String msg = "请求失败";
    private Object data;

    public JsonResult(boolean success) {
        this.status = success ? "200" : "400";
        this.msg = success ? "成功" : "失败";
    }

    public JsonResult(boolean success, String msg) {
        this.status = success ? RET_SUCCESS : RET_ERROR;
        this.msg = msg;
    }

    public JsonResult(boolean success, String msg, Object data) {
        this.status = success ? RET_SUCCESS : RET_ERROR;
        this.msg = msg;
        this.data = data;
    }

    public JsonResult(String status, String msg) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    @Deprecated
    public JsonResult(String status, String msg, Object data, String token) {
        this(status, msg, data);
    }

    public JsonResult(String status, String msg, Object data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public JsonResult success() {
        this.status = RET_SUCCESS;
        this.msg = "成功";
        return this;
    }

    public JsonResult success(String msg) {
        this.status = RET_SUCCESS;
        this.msg = msg;
        return this;
    }

    public JsonResult error(String msg) {
        this.status = RET_ERROR;
        this.msg = msg;
        return this;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
